package com.ljy.tkuser.config;

import com.baomidou.mybatisplus.core.injector.ISqlInjector;
import com.baomidou.mybatisplus.extension.injector.LogicSqlInjector;
import com.baomidou.mybatisplus.extension.plugins.OptimisticLockerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import com.baomidou.mybatisplus.extension.plugins.PerformanceInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

@Configuration
@MapperScan("com.ljy.tkuser.mapper")
public class MpConfig {
    //乐观锁配置类
    @Bean
    public OptimisticLockerInterceptor optimisticLockerInterceptor(){
        return new OptimisticLockerInterceptor();
    }

    //分页插件
 @Bean
  public PaginationInterceptor paginationInterceptor(){ return new PaginationInterceptor(); }

    //逻辑删除
    @Bean
    public ISqlInjector sqlInjector(){ return  new LogicSqlInjector(); }

    //性能分析插件
    //三种环境 dev test prod
    @Bean
    @Profile({"dev","test"})
    public PerformanceInterceptor performanceInterceptor(){
        PerformanceInterceptor performanceInterceptor = new PerformanceInterceptor();
        performanceInterceptor.setMaxTime(100000);  //超时时间 达到超时时间会报错
        performanceInterceptor.setFormat(true);
        return performanceInterceptor;
    }
}
